package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysVideoDetailQuery;
import net.learn.system.query.SysVideoQuery;
import net.learn.system.service.SysVideoDetailService;
import net.learn.system.vo.SysVideoDetailVO;
import net.learn.system.vo.SysVideoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 视频管理
 */
@RestController
@RequestMapping("sys/videodetail")
@Tag(name="视频管理")
@AllArgsConstructor
public class SysVideoDetailController {
    @Autowired
    SysVideoDetailService videoDetailService;

    @GetMapping("getVideoDetail")
    @Operation(summary = "分页获视频扩展列表")
    public Result<PageResult<SysVideoDetailVO>> getVideoDetail(@Valid SysVideoDetailQuery query){
        PageResult<SysVideoDetailVO> page = videoDetailService.qryVideoDetailListPage(query);
        return Result.ok(page);
    }
    @PutMapping
    @Operation(summary = "修改视频扩展")
    public Result<String> updateVideoDetail(@RequestBody @Valid List<SysVideoDetailVO> qryList){
        for (SysVideoDetailVO detail:qryList){
            if(detail.getId().toString()==""){
                videoDetailService.addVideoDetail(detail);
            }else {
                SysVideoDetailQuery query=new SysVideoDetailQuery();
                query.setId(detail.getId());
                List<SysVideoDetailVO> volist=videoDetailService.qryVideoDetailList(query);
                if(volist.size()>0){
                    videoDetailService.updateVideoDetail(detail);
                }
            }
        }
        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增视频扩展")
    public Result<String> addVideoDetail(@RequestBody List<SysVideoDetailVO> qryList){
        for (SysVideoDetailVO detail:qryList){

            videoDetailService.addVideoDetail(detail);
        }
        return Result.ok();
    }
    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> delete(@RequestBody List<Long> idList){
        videoDetailService.delete(idList);
        return Result.ok();
    }
    @PostMapping("getVideoDetailList")
    @Operation(summary = "获取视频扩展列表")
    public Result<List<SysVideoDetailVO>> getVideoDetailList(@RequestBody @Valid SysVideoDetailQuery query){
        List<SysVideoDetailVO> list = videoDetailService.qryVideoDetailList(query);
        return Result.ok(list);
    }
}

